package com.learn.springboot3.controller;


import cn.hutool.core.lang.UUID;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

@RestController
@RequestMapping("redisson")

public class RedissonController {


    private static final Logger log = LoggerFactory.getLogger(RedissonController.class);
    @Autowired
    RedissonClient redissonClient;

    @GetMapping
    public String redisson() throws FileNotFoundException {

        long l = System.currentTimeMillis();

        for (int i = 0; i < 1000; i++) {
            String key = UUID.randomUUID().toString(true);

            RLock lock = redissonClient.getLock(key);
            boolean b = lock.tryLock();


        }
        long l2 = System.currentTimeMillis();
       Long time= (l2-l)/1000;


        return time.toString()+":"+(l2-l) ;

    }
}
